home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / pinfocom_3_0.lha / Source / property.c < prev    next >
C/C++ Source or Header  |  1992-10-22  |  5KB  |  221 lines

  1. /* property.c
  2.  *
  3.  *  ``pinfocom'' -- a portable Infocom Inc. data file interpreter.
  4.  *  Copyright (C) 1987-1992  InfoTaskForce
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; see the file COPYING.  If not, write to the
  18.  *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * $Header: RCS/property.c,v 3.0 1992/10/21 16:56:19 pds Stab $
  23.  */
  24.  
  25. #include    "infocom.h"
  26.  
  27. static property
  28. prop_addr A1(object_t *, obj)
  29. {
  30.     extern byte     *base_ptr;
  31.  
  32.     property        p;
  33.  
  34.     p = base_ptr + Z_TO_WORD(obj->data);
  35.     return (p + (Z_TO_BYTE(p) << 1) + 1);
  36. }
  37.  
  38. static property
  39. next_addr A1(property, p)
  40. {
  41.     return (p + (Z_TO_BYTE(p) >> 5) + 2);
  42. }
  43.  
  44. void
  45. next_prop A2(word, obj_num, word, prop_num)
  46. {
  47.     property    p;
  48.     word        p_num;
  49.  
  50.     p = prop_addr(obj_addr(obj_num));
  51.     if (prop_num != 0)
  52.     {
  53.         p_num = *p & 0x1F;
  54.  
  55.         /* Properties are kept in descending order */
  56.  
  57.         while (p_num > prop_num)
  58.         {
  59.             p = next_addr(p);
  60.             p_num = *p & 0x1F;
  61.         }
  62.         if (p_num < prop_num)
  63.             error("prop: Error retrieving next property ($%02x)", prop_num);
  64.         else
  65.             p = next_addr(p);
  66.     }
  67.  
  68.     store((word)(*p & 0x1F));
  69. }
  70.  
  71. void
  72. put_prop A3(word, obj_num, word, prop_num, word, value)
  73. {
  74.     property        p;
  75.     word            p_num;
  76.  
  77.     p = prop_addr(obj_addr(obj_num));
  78.     p_num = *p & 0x1F;
  79.  
  80.     /* Properties are kept in descending order */
  81.  
  82.     while (p_num > prop_num)
  83.     {
  84.         p = next_addr(p);
  85.         p_num = *p & 0x1F;
  86.     }
  87.     if (p_num < prop_num)
  88.         error("prop: Error storing property ($%02x)", prop_num);
  89.     else
  90.     {
  91.         if ((*p++) & 0x20)
  92.         {
  93.             (*p++) = value >> 8;
  94.             *p = value;
  95.         }
  96.         else
  97.             *p = value;
  98.     }
  99. }
  100.  
  101. void
  102. get_prop A2(word, obj_num, word, prop_num)
  103. {
  104.     property        p;
  105.     word            p_num;
  106.     word            prop;
  107.  
  108.     p = prop_addr(obj_addr(obj_num));
  109.     p_num = *p & 0x1F;
  110.  
  111.     /* Properties are kept in descending order */
  112.  
  113.     while (p_num > prop_num)
  114.     {
  115.         p = next_addr(p);
  116.         p_num = *p & 0x1F;
  117.     }
  118.     if (p_num < prop_num)
  119.     {
  120.         prop_num = (--prop_num) << 1;
  121.         p = (property) objd.obj_base + prop_num;
  122.         prop = Z_TO_WORD(p);
  123.     }
  124.     else
  125.     {
  126.         if (*(p++) & 0x20)
  127.             prop = Z_TO_WORD(p);
  128.         else
  129.             prop = Z_TO_BYTE(p);
  130.     }
  131.     store(prop);
  132. }
  133.  
  134. void
  135. get_prop_addr A2(word, obj_num, word, prop_num)
  136. {
  137.     extern byte     *base_ptr;
  138.  
  139.     property        p;
  140.     word            p_num;
  141.  
  142.     p = prop_addr(obj_addr(obj_num));
  143.     p_num = *p & 0x1F;
  144.  
  145.     /* Properties are kept in descending order */
  146.  
  147.     while (p_num > prop_num)
  148.     {
  149.         p = next_addr(p);
  150.         p_num = *p & 0x1F;
  151.     }
  152.     if (p_num < prop_num)
  153.         store(0);
  154.     else
  155.         store((word)(p + 1 - base_ptr));
  156. }
  157.  
  158. void
  159. get_prop_len A1(word, prop_num)
  160. {
  161.     extern byte     *base_ptr;
  162.  
  163.     property        p;
  164.  
  165.     p = base_ptr + prop_num - 1;
  166.     store((word)((Z_TO_BYTE(p) >> 5) + 1));
  167. }
  168.  
  169. void
  170. load_word_array A2(word, base, word, offset)
  171. {
  172.     word    page;
  173.     word    page_offset;
  174.  
  175.     base += (offset << 1);
  176.     page = base / BLOCK_SIZE;
  177.     page_offset = base % BLOCK_SIZE;
  178.     store(get_word(&page, &page_offset));
  179. }
  180.  
  181. void
  182. load_byte_array A2(word, base, word, offset)
  183. {
  184.     word    page;
  185.     word    page_offset;
  186.  
  187.     base += offset;
  188.     page = base / BLOCK_SIZE;
  189.     page_offset = base % BLOCK_SIZE;
  190.     store((word)get_byte(&page, &page_offset));
  191. }
  192.  
  193. void
  194. save_word_array A3(word, base, word, offset, word, value)
  195. {
  196.     extern byte     *base_ptr;
  197.  
  198.     byte            *ptr;
  199.  
  200.     /* The quantity added to 'base_ptr' must be a word */
  201.  
  202.     base += (offset << 1);
  203.     ptr = base_ptr + base;
  204.     (*ptr++) = value >> 8;
  205.     *ptr = value;
  206. }
  207.  
  208. void
  209. save_byte_array A3(word, base, word, offset, word, value)
  210. {
  211.     extern byte     *base_ptr;
  212.  
  213.     byte            *ptr;
  214.  
  215.     /* The quantity added to 'base_ptr' must be a word */
  216.  
  217.     base += offset;
  218.     ptr = base_ptr + base;
  219.     *ptr = value;
  220. }
  221.